/*
	rectModel
	The object for the rect which will be the player.
	
	possible args:
	radius:double
	latNum:int
	lonNum:int
*/
function RampModel (){
    setDefaults(this);
    this.color = [0.3, 0.7, 0.3, 1.0];
	var depth = 15.0;

    var splitData = [];
	
	this.create = function(func, sliceNum, width, height){
		sliceNum = Math.round(sliceNum);
        this.width = width;
        this.height = height;
		res = 1.0 / sliceNum;
		
		
		var count = 0;
		//front
		for(var f = 0.0; f <= 1.0 + res / 2.0; f += res){
			this.pushVertex(f, func(f), depth);
			this.pushVertex(f, 0.0, depth);
			this.normalData.push(0.0, 0.0, 1.0);
			this.normalData.push(0.0, 0.0, 1.0);
			count += 2;
		}
		splitData.push(count);
		
		//right
		this.pushVertex(1.0, 0.0, -depth);
		
		this.pushVertex(1.0, func(1.0), -depth);
		
		this.pushVertex(1.0, 0.0, depth);
		this.pushVertex(1.0, func(1.0), depth);
		
		this.normalData.push(1.0, 0.0, 0.0);
		this.normalData.push(1.0, 0.0, 0.0);
		this.normalData.push(1.0, 0.0, 0.0);
		this.normalData.push(1.0, 0.0, 0.0);
		
		splitData.push(4);
		
		
		//top
		for(var f = 0.0; f <= 1 + res/2.0; f += res){
			this.pushVertex(f, func(f), -depth);
			this.pushVertex(f, func(f), depth);
			
			var cross0 = vec3.create([f, func(f), 0.0]);
			var cross1 = vec3.create([f + .001, func(f + .001), 0.0]);
			
			vec3.subtract(cross0, cross1, cross0);
			
			var cross3 = vec3.create([0.0,0.0, depth]);
			
			vec3.cross(cross0, cross3, cross0);
			vec3.normalize(cross0, cross0);
			var pushArray = [cross0[0], cross0[1], cross0[2]];
			
			this.normalData.push(pushArray[0]);
			this.normalData.push(pushArray[1]);
			this.normalData.push(pushArray[2]);
			this.normalData.push(pushArray[0]);
			this.normalData.push(pushArray[1]);
			this.normalData.push(pushArray[2]);
		}
		splitData.push(count);
		 
		//left
		this.pushVertex(0.0, func(0.0), -depth);
		this.pushVertex(0.0, 0.0, -depth);
		this.pushVertex(0.0, func(0.0), depth);
		this.pushVertex(0.0, 0.0, depth);
		
		this.normalData.push(-1.0, 0.0, 0.0);
		this.normalData.push(-1.0, 0.0, 0.0);
		this.normalData.push(-1.0, 0.0, 0.0);
		this.normalData.push(-1.0, 0.0, 0.0);
		splitData.push(4);
		
		//bottom
		this.pushVertex(0.0,0.0,depth);
		this.pushVertex(1.0, 0.0, depth);
		
		this.pushVertex(0.0, 0.0, -depth);
		this.pushVertex(1.0, 0.0, -depth);

		this.normalData.push(0.0, -1.0, 0.0);
		this.normalData.push(0.0, -1.0, 0.0);
		this.normalData.push(0.0, -1.0, 0.0);
		this.normalData.push(0.0, -1.0, 0.0);
		
		splitData.push(4);
		//Back
		for(var f = 0.0; f <= 1.0 + res / 2.0; f += res){
		
			this.pushVertex(f, func(f), -depth);
			this.pushVertex(f, 0.0, -depth);
			
			this.normalData.push(0.0,0.0,-1.0);
			this.normalData.push(0.0,0.0,-1.0);
		}
		splitData.push(count);
        this.initBuffers();
	}

    this.pushVertex = function(x, y, z) {
        this.vertexData.push(x * this.width, y * this.height, z);
    }


    this.draw = function(camera) {
        this.prepareDraw(camera);
		var currSplit = 0;
		for(var i = 0; i < splitData.length; i++){
			gl.drawArrays(gl.TRIANGLE_STRIP, currSplit, splitData[i]);
			currSplit += splitData[i];
		}
		
    }
}
